From fbf495f1d354904a3102ae78a58d5b0c9a4e8007 Mon Sep 17 00:00:00 2001 From: Nicolas Koch Date: Mon, 31 Aug 2015 12:07:50 +0200 Subject: [PATCH] Use internal error instead of ProcessError when multiple tests fail --- src/bin/bench.rs | 5 +---- src/bin/test.rs | 5 +---- src/cargo/ops/cargo_test.rs | 30 ++++++++++++------------------ tests/test_cargo_bench.rs | 2 +- 4 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/bin/bench.rs b/src/bin/bench.rs index 932dae310..c90bdba2d 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -95,10 +95,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { match err { None => Ok(None), Some(err) => { - Err(match err.exit.as_ref().and_then(|c| c.code()) { - Some(i) => CliError::new("", i), - None => CliError::from_error(Human(err), 101) - }) + Err(CliError::from_error(Human(err), 101)) } } } diff --git a/src/bin/test.rs b/src/bin/test.rs index ade460165..424e8519c 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -101,10 +101,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { match err { None => Ok(None), Some(err) => { - Err(match err.exit.as_ref().and_then(|e| e.code()) { - Some(i) => CliError::new("", i), - None => CliError::from_error(Human(err), 101) - }) + Err(CliError::from_error(Human(err), 101)) } } } diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 71636b76d..6c7227cc2 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -4,7 +4,7 @@ use std::path::Path; use core::Source; use sources::PathSource; use ops::{self, ExecEngine, ProcessEngine, Compilation}; -use util::{self, CargoResult, ProcessError, process_error}; +use util::{self, CargoResult, CargoError, internal}; pub struct TestOptions<'a> { pub compile_opts: ops::CompileOptions<'a>, @@ -15,7 +15,7 @@ pub struct TestOptions<'a> { #[allow(deprecated)] // connect => join in 1.3 pub fn run_tests(manifest_path: &Path, options: &TestOptions, - test_args: &[String]) -> CargoResult> { + test_args: &[String]) -> CargoResult>> { let config = options.compile_opts.config; let (compile, error) = try!(build_and_run(manifest_path, options, test_args)); @@ -36,7 +36,7 @@ pub fn run_tests(manifest_path: &Path, .filter(|t| t.doctested()) .map(|t| (t.src_path(), t.name(), t.crate_name())); - let mut process_errors = match error { + let mut errors = match error { None => Vec::new(), Some(err) => vec![err], }; @@ -91,21 +91,18 @@ pub fn run_tests(manifest_path: &Path, shell.status("Running", p.to_string()) })); if let Err(e) = ExecEngine::exec(&mut ProcessEngine, p) { - process_errors.push(e); + errors.push(Box::new(e)); if !options.no_fail_fast { break } } } - if process_errors.is_empty() { + if errors.is_empty() { Ok(None) - } else if process_errors.len() == 1 { - Ok(Some(process_errors.pop().unwrap())) + } else if errors.len() == 1 { + Ok(Some(errors.pop().unwrap())) } else { - let err = process_error("Multiple tests failed", - None, - process_errors[0].exit.as_ref(), - process_errors[0].output.as_ref()); + let err = internal("Multiple tests failed"); Ok(Some(err)) } @@ -113,7 +110,7 @@ pub fn run_tests(manifest_path: &Path, pub fn run_benches(manifest_path: &Path, options: &TestOptions, - args: &[String]) -> CargoResult> { + args: &[String]) -> CargoResult>> { let mut args = args.to_vec(); args.push("--bench".to_string()); @@ -128,7 +125,7 @@ pub fn run_benches(manifest_path: &Path, fn build_and_run<'a>(manifest_path: &Path, options: &TestOptions<'a>, test_args: &[String]) - -> CargoResult<(Compilation<'a>, Option)> { + -> CargoResult<(Compilation<'a>, Option>)> { let config = options.compile_opts.config; let mut source = try!(PathSource::for_path(&manifest_path.parent().unwrap(), config)); @@ -165,13 +162,10 @@ fn build_and_run<'a>(manifest_path: &Path, Ok((compile, None)) } else if errors.len() == 1 { // Just one error occured => we can return it. - Ok((compile, Some(errors.pop().unwrap()))) + Ok((compile, Some(Box::new(errors.pop().unwrap())))) } else { // Multiple tests failed => Create a more generic error - let err = process_error("Multiple tests failed", - None, - errors[0].exit.as_ref(), - errors[0].output.as_ref()); + let err = internal("Multiple tests failed"); Ok((compile, Some(err))) } } diff --git a/tests/test_cargo_bench.rs b/tests/test_cargo_bench.rs index 9d0123ec6..5e3b21cad 100644 --- a/tests/test_cargo_bench.rs +++ b/tests/test_cargo_bench.rs @@ -192,7 +192,7 @@ test bench_hello ... ", thread '
' panicked at 'assertion failed: \ `(left == right)` (left: \ `\"hello\"`, right: `\"nope\"`)', src[..]foo.rs:14 - +[..] ") .with_status(101)); }); -- 2.30.2